#include <bits/stdc++.h>

using namespace std;
#define int long long
const int inf = 0x3f3f3f3f;

void solve()
{
    string s;
    cin >> s;
    int ans = 0;
    int i;
    for (i = s.size() - 1; i >= 0; i--)
    {
        if (s[i] == '0') ans++;
        else break;
    }
    i--;
    while (i >= 0)
    {
        if (s[i--] != '0')
            ans++;
    }
    cout << ans << endl;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int _ = 1;
    cin >> _;
    while (_--)
    {
        solve();
    }
    return 0;
}